package test0828;

import com.sun.deploy.util.StringUtils;

import java.util.Arrays;
import java.util.stream.Collectors;

public class test2 {
    public static boolean isIpv4(String mes) {
        String[] mes1 = StringUtils.splitString(mes, ":");
        if (mes1.length != 4) {
            return false;
        }
        int size = Arrays.stream(mes1).collect(Collectors.toList()).stream()
                .filter(e -> ((Character) e.charAt(0)).equals("0") || Integer.parseInt(e) > 255 || Integer.parseInt(e) < 0)
                .collect(Collectors.toList())
                .size();
        if (size == 0) {
            return true;
        } else {
            return false;
        }

    }

    public static boolean isIpv6(String mes) {
        String[] mes1 = StringUtils.splitString(mes, ":");
        if (mes1.length != 8) {
            return false;
        }
        int size = Arrays.stream(mes1).collect(Collectors.toList()).stream()
                .filter(e -> e.length() != 4).collect(Collectors.toList()).size();
        if (size != 0) {
            return false;
        } else {
            return true;
        }
    }

    public static void main(String[] args) {
        String a = "1111:1111:1111:1111:1111:1111::1111";
        boolean flag1 = isIpv4(a);
        boolean flag2 = isIpv6(a);
        if(flag1){
            System.out.println("ipv4");
        }
        if(flag2){
            System.out.println("ipv6");
        }
     if(!flag1&&!flag2){
         System.out.println("11111111");
     }
    }
}